/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package produccion.vistas;

import produccion.controlador.ControladorProduccion;
import Reporte.Reporte;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
import java.util.List;
import modelos.Actividad;
import modelos.Producto;
import modelos.Turno;

/**
 *
 * @author James
 */
public class ReporteProduccionPorObrero extends javax.swing.JInternalFrame {
    private int turnoSeleccionado;
    private int actividadSeleccionada;
    List<Actividad> listaActividades;
    List<Turno> listaTurnos;
    /**
     * Creates new form ReporteProduccionPorObrero
     */
    public ReporteProduccionPorObrero() {
        initComponents();
        dpFechaInicio.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                // the docs of JDateChooser says that when the date is modified, a "date" property change is fired
                if (evt.getPropertyName().equals("date")) {
                    dpFechaFin.setMinSelectableDate(dpFechaInicio.getDate());
                }
            }
        });
        dpFechaFin.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                // the docs of JDateChooser says that when the date is modified, a "date" property change is fired
                if (evt.getPropertyName().equals("date")) {
                    dpFechaInicio.setMaxSelectableDate(dpFechaFin.getDate());
                }
            }
        });
        
        listaActividades= ControladorProduccion.seleccionarActividades();
        listaTurnos = ControladorProduccion.seleccionarTurnos();
        
        cbActividad.removeAllItems();
        for(int i=0;i<listaActividades.size();i++){
            cbActividad.addItem(listaActividades.get(i).getNombre());
        }
        cbTurno.removeAllItems();
        for(int i=0;i<listaTurnos.size();i++){
            cbTurno.addItem(listaTurnos.get(i).getNombre());
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dpFechaFin = new com.toedter.calendar.JDateChooser();
        dpFechaInicio = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbTurno = new javax.swing.JComboBox();
        cbActividad = new javax.swing.JComboBox();
        btnGenerar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Reporte de Produccion Por Obrero");

        dpFechaFin.setDateFormatString("dd/MM/yyyy");

        dpFechaInicio.setDateFormatString("dd/MM/yyyy");

        jLabel2.setText("Fecha Fin");

        jLabel1.setText("Fecha Inicio");

        jLabel3.setText("Turno:");

        jLabel4.setText("Actividad:");

        cbTurno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbTurno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTurnoActionPerformed(evt);
            }
        });

        cbActividad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbActividad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbActividadActionPerformed(evt);
            }
        });

        btnGenerar.setText("Generar");
        btnGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGenerarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dpFechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(dpFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbActividad, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnGenerar)
                .addGap(126, 126, 126))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(dpFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dpFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(cbTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbActividad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addComponent(btnGenerar)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGenerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerarActionPerformed
        // TODO add your handling code here:
        Date fechaInicio, fechaFin;
        fechaInicio = new Date(0000,01,01);
        fechaFin = new Date(9999,12,25);
        if(dpFechaInicio.getDate() != null) fechaInicio=dpFechaInicio.getDate();
        if(dpFechaFin.getDate() != null) fechaFin=dpFechaFin.getDate();
        Reporte.reporteProduccionPorObreroConParametros("ProduccionPorObrero", "src/Reporte/Produccion/ProduccionPorObrero/ProduccionPorObrero.jasper", "src/Reporte/LBJ-ProduccionPorObrero.pdf",fechaInicio,fechaFin,listaActividades.get(actividadSeleccionada).getIdactividad(),listaTurnos.get(turnoSeleccionado).getIdturno());
    }//GEN-LAST:event_btnGenerarActionPerformed

    private void cbTurnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTurnoActionPerformed
        // TODO add your handling code here:
        turnoSeleccionado = cbTurno.getSelectedIndex();
    }//GEN-LAST:event_cbTurnoActionPerformed

    private void cbActividadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbActividadActionPerformed
        // TODO add your handling code here:
        actividadSeleccionada= cbActividad.getSelectedIndex();
    }//GEN-LAST:event_cbActividadActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGenerar;
    private javax.swing.JComboBox cbActividad;
    private javax.swing.JComboBox cbTurno;
    private com.toedter.calendar.JDateChooser dpFechaFin;
    private com.toedter.calendar.JDateChooser dpFechaInicio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
